package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocSpouseDao;
import com.irdstudio.cdp.pboc.service.domain.PbocSpouse;
import com.irdstudio.cdp.pboc.service.facade.PbocSpouseService;
import com.irdstudio.cdp.pboc.service.vo.PbocSpouseVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 配偶信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocSpouseService")
public class PbocSpouseServiceImpl implements PbocSpouseService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocSpouseServiceImpl.class);

	@Autowired
	private PbocSpouseDao pbocSpouseDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocSpouse(PbocSpouseVO inPbocSpouseVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocSpouseVo.toString());
		int num = 0;
		try {
			PbocSpouse pbocSpouse = new PbocSpouse();
			beanCopy(inPbocSpouseVo, pbocSpouse);
			num = pbocSpouseDao.insertPbocSpouse(pbocSpouse);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocSpouseVO inPbocSpouseVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocSpouseVo);
		int num = 0;
		try {
			PbocSpouse pbocSpouse = new PbocSpouse();
			beanCopy(inPbocSpouseVo, pbocSpouse);
			num = pbocSpouseDao.deleteByPk(pbocSpouse);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocSpouseVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocSpouseVO inPbocSpouseVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocSpouseVo.toString());
		int num = 0;
		try {
			PbocSpouse pbocSpouse = new PbocSpouse();
			beanCopy(inPbocSpouseVo, pbocSpouse);
			num = pbocSpouseDao.updateByPk(pbocSpouse);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocSpouseVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocSpouseVO queryByPk(PbocSpouseVO inPbocSpouseVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocSpouseVo);
		try {
			PbocSpouse queryPbocSpouse = new PbocSpouse();
			beanCopy(inPbocSpouseVo, queryPbocSpouse);
			PbocSpouse queryRslPbocSpouse = pbocSpouseDao.queryByPk(queryPbocSpouse);
			if (Objects.nonNull(queryRslPbocSpouse)) {
				PbocSpouseVO outPbocSpouseVo = beanCopy(queryRslPbocSpouse, new PbocSpouseVO());
				logger.debug("当前查询结果为:"+ outPbocSpouseVo.toString());
				return outPbocSpouseVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSpouseVO> queryAllOwner(PbocSpouseVO pbocSpouseVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocSpouseVO> list = null;
		try {
			List<PbocSpouse> pbocSpouses = pbocSpouseDao.queryAllOwnerByPage(pbocSpouseVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocSpouses.size());
			pageSet(pbocSpouses, pbocSpouseVo);
			list = (List<PbocSpouseVO>) beansCopy(pbocSpouses, PbocSpouseVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSpouseVO> queryAllCurrOrg(PbocSpouseVO pbocSpouseVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocSpouse> pbocSpouses = pbocSpouseDao.queryAllCurrOrgByPage(pbocSpouseVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocSpouses.size());
		List<PbocSpouseVO> list = null;
		try {
			pageSet(pbocSpouses, pbocSpouseVo);
			list = (List<PbocSpouseVO>) beansCopy(pbocSpouses, PbocSpouseVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSpouseVO> queryAllCurrDownOrg(PbocSpouseVO pbocSpouseVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocSpouse> pbocSpouses = pbocSpouseDao.queryAllCurrDownOrgByPage(pbocSpouseVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocSpouses.size());
		List<PbocSpouseVO> list = null;
		try {
			pageSet(pbocSpouses, pbocSpouseVo);
			list = (List<PbocSpouseVO>) beansCopy(pbocSpouses, PbocSpouseVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
